<?php
/**
 * 将CSDN中的邮箱存到一个文件
 * 
 * zdg # 12344321 # zdg@csdn.net
 * LaoZheng # 670203313747 # chengming_zheng@163.com
 */
exit("处理好");
$s = microtime(true);

set_time_limit(0);
$s = microtime(true);
$file_dir = 'C:\csdn_all.sql';


$file = fopen ( $file_dir, "r" );
if(!$file){
	echo "文件打不开或不存在1";
	exit;
}

$write = fopen("csdn_email.txt", "a");
if(!$write){
	echo "文件打不开或不存在2";
	exit;
}

/*从文件中每次读一行，将Email存入数据库*/
$i = 0;
while ( !feof($file) ){
	$str = explode("#", fgets ( $file ));
	$email = trim($str[2]);
	if(empty($email))
		continue;
	
	if(check_email($email)){
		fwrite($write, $email.";");
		$i++;
	}
	
}

fclose($file);
fclose($write);

echo $i."<br>";
echo "用时:".number_format(microtime(true) - $s, 3, '.', '');

function check_email($str){
	return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$str))?true:false;
}